/**
 * @author: dn-jinmin/dn-jinmin
 * @doc:
 */

package main

import "fmt"

// 状态接口
type State interface {
	Name() string
	DoAction(context *Context)
}

// 上下文对象
type Context struct {
	currentState State
}

func (c *Context) SetState(state State) {
	c.currentState = state
}

func (c *Context) GetCurrentState() State {
	return c.currentState
}

// 停止状态
type StopState struct{}

func (s *StopState) Name() string {
	return "Stop State"
}

func (s *StopState) DoAction(context *Context) {
	fmt.Println("Elevator is stopped")
	context.SetState(s)
}

// 运行状态
type RunState struct{}

func (r *RunState) Name() string {
	return "Run State"
}

func (r *RunState) DoAction(context *Context) {
	fmt.Println("Elevator is running")
	context.SetState(r)
}

// 维修状态
type RepairState struct{}

func (r *RepairState) Name() string {
	return "Repair State"
}

func (r *RepairState) DoAction(context *Context) {
	fmt.Println("Elevator is under repair")
	context.SetState(r)
}

func main() {
	context := &Context{}

	stopState := &StopState{}
	stopState.DoAction(context)

	runState := &RunState{}
	runState.DoAction(context)

	repairState := &RepairState{}
	repairState.DoAction(context)
}
